/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var enmu = require("enums");
	var user = require("store").get("user");
	var subnavEvents = require("../handler/subnavEvents")
    var instance = {
        initComponent: function (params,widget) {
        	var subnav = new Subnav({
        		parentNode:".J-subnav",
        		model:{
        			title:"团队退房结算",
        			items:[{
        				id: "alliance",
        				type: "buttongroup",
        				tip:"机构",
        				lazy: true,
        				all: {
							show: true,
							position: "top",
						},
        				items: [{
        					key: "false",
							value: "本机构"
						},{
							key: "true",
							value: "联盟单位"
        				}],
        				handler: function(){
        					widget.get("grid").refresh();
        				}
        			},{
        				id: "servicePoint",
						type: "buttongroup",
//						url: "api/servicepoint/operableservicepoints",
//						lazy: true,
						items:user.privateServicePoints,
						tip: "服务点",
						keyField: "pkServicePoint",
						valueField: "name",
						handler: function(){
							widget.get("grid").refresh();
						}
        			},{
        				id:"statementStatus",
        				tip:"结算状态",
        				type:"buttongroup",
        				items:enmu["com.eling.elcms.travel.model.CheckInImplement.StatementStatus"],
        				handler: function(){
        					widget.get("grid").refresh();
        				}
        			},{
        				id: "paymentMethod",
        				type: "buttongroup",
        				tip:"结算方式",
        				all: {
							show: true,
							position: "top",
						},
						  items: [{
					          key: "Cash",
					          value: "现金"
					        }, {
						      key: "WipeCard",
						      value: "刷卡"
						    }, {
							  key: "Transfer",
							  value: "转账"
							}, {
							  key: "OnCredit",
							  value: "挂账"
							}],
						handler: function(key){
							widget.get("grid").refresh();
						}
        			},{
        				id: "destination",
						type: "buttongroup",
						url: "api/destination/query",
						tip: "目的地",
						keyField: "pkDestination",
						valueField: "name",
						all: {
							show: true,
							position: "top",
						},
						handler: function(){
							widget.get("grid").refresh();
						}
        			},{
        				id: "time",
        				type: "daterange",
        				tip: "退房日期",
        				ranges:{
	        				"今天": [moment().startOf("days"), moment().endOf("days")],
	 			            "本月": [moment().startOf("month"), moment().endOf("month")]
						},
						defaultRange: "本月",
        				handler: function(){
        					widget.get("grid").refresh();
        				}
        			},{
        				id: "save",
        				type: "button",
						text: "保存",
						show: false,
						handler: function(){
							subnavEvents.save(widget);
							widget.detail = false;
						}	
        			},{
        				id: "return",
        				type: "button",
						text: "返回",
						show: false,
						handler: function(){
							widget.detail = false;
							
							var forms = widget.get("onCreditForm");
        					if(forms){
        						forms.destroy();
        					}
        					
							
							widget.show([".J-grid"]).hide([".J-form",".J-endGrid",".J-total",".J-detailForm",".J-onCreditForm"]);
							widget.get("subnav").hide(["return","save","totalprint"]).show(["paymentMethod","statementStatus","alliance","servicePoint","destination", "time"]);
							widget.get("grid").refresh();
						}
        				
        			},{
        				id: "print",
        				type: "button",
						text: "个人明细打印",
						show: false,
						handler: function(){
							widget.handler.print(widget);
						}
        			},{
        				id: "totalprint",
        				type: "button",
						text: "结算单打印",
						show: false,
						handler: function(){
							var teamType = widget.get("teamType");
							
							var idata = {};
							idata["teamType"] = teamType;
							var endGrid = widget.get("endGrid").getData();
							var personal = [];
							for(var i=0;i<endGrid.length;i++){
								var personalObj = {};
								personalObj.name = endGrid[i].signUpRegister.personalInfo.name;
								personalObj.code = endGrid[i].roomRegister.room.code;
								personal.push(personalObj);
							}
							idata["endGrid"] = personal;
							if(teamType == "直属入住联盟"){
								idata["tatalGrid"] = widget.get("alltotalGrid").getData();
								
								var allform = widget.get("allform");
								var allFormData = allform.getData();
								idata.destination = allFormData["allianceConfirm.groupReserve.planItemGroup.planItem.destination.name"];
								idata.signUpNumber = allFormData["signUpNumber"];
								idata.checkInDate = allFormData["allianceConfirm.groupReserve.checkInDate"];
								idata.checkOutDate = allFormData["allianceConfirm.groupReserve.checkOutDate"];
								idata.operatorName = allFormData["allianceSettlement.operator.name"];
								idata.statementDate = allFormData["allianceSettlement.settlementDate"];
							}else{
								idata["tatalGrid"] = widget.get("totalGrid").getData();
								
								var allform = widget.get("form");
								var allFormData = allform.getData();
								idata.destination = allFormData["destinationName"];
								idata.signUpNumber = allFormData["signUpNum"];
								idata.checkInDate = allFormData["checkInDate"];
								idata.checkOutDate = allFormData["checkOutDate"];
								idata.operatorName = allFormData["operatorName"];
								idata.statementDate = allFormData["statementDate"];
							}
							
							window.open("assets/eling/elcms/travel/plancheckoutsettlement/src/plancheckoutprint.html?obj="+JSON.stringify(idata));
						}
        			}]
        		}
        	});
        	widget.set("subnav",subnav);
        }
    };
    module.exports = instance;
});
